<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SEE DEMO</title>
</head>
<body>
<div id="msgFrompPush"></div>
<script>
    if(!!window.EventSource){
        var source=new EventSource();
        s='';
        source.addEventListener("message",function (e) {
            s+=e.data+"<br/>";
            document.getElementById("msgFrompPush").innerHTML=s;
        });

        source.addEventListener("open",function (e) {
            console.log("open connection");
        });
        source.addEventListener("error",function (e) {
            if(e.readyState==EventSource.CLOSED){
                alert("连接关闭");
            }else{
                alert(e.readyState);
            }
        })
    }else{
        alert("浏览器不支持sse")
    }
</script>
</body>
</html>